const axios = require('axios');
const qs = require('qs');


var getUrl = "http://localhost:8088/getUrl";
var postUrl = "http://localhost:8088/postUrl";
var putUrl = "http://localhost:8088/putUrl";
var deleteUrl = "http://localhost:8088/deleteUrl";


axios({
  method: 'get',
  url: 'http://localhost:8088/getUrl?name=markix'
}).then(function (resp) {
  console.log("get", resp.data);
});
//等价于这个写法，注意url是特殊的单引号，该语法为"模板字符串"
axios.get(`${getUrl}`, {
    params: {
      "name": "markix"
    }
  })
  .then(function (resp) {
    console.log("get params", resp.data);
  });


//发送请求体，content-type: "application/json"
axios.post(`${postUrl}`, {
    "name": "markix"
  })
  .then(function (resp) {
    console.log("post json", resp.data);
  });

//发送表单，content-type: "application/x-www-form-urlencoded"
axios.post(`${postUrl}`, qs.stringify({
    "name": "markix"
  }))
  .then(function (resp) {
    console.log("post form", resp.data);
  });


axios.put(`${putUrl}`, {
    "name": "markix"
  })
  .then(function (resp) {
    console.log("put json", resp.data);
  });


axios.delete(`${deleteUrl}`, {
    data: {
      "name": "markix"
    }
  })
  .then(function (resp) {
    console.log("delete json", resp.data);
  });